package com.huel.components;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.huel.bean.Btn;
import com.huel.bean.Goods;
import com.huel.taobaostore.R;

import java.util.List;

public class ShowGoodsRecycleViewAdapter extends RecyclerView.Adapter<ShowGoodsRecycleViewAdapter.ViewHolder> {

    private List<Goods> mList;

    public void setmList(List<Goods> mList) {
        this.mList = mList;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        View myView;
        ImageView imageView1, imageView2;
        TextView title;

        public ViewHolder(View itemView) {
            super(itemView);
            myView = itemView;
            imageView1 = (ImageView) itemView.findViewById(R.id.iv1);
            title = itemView.findViewById(R.id.goodsTitle);
        }
    }

    public ShowGoodsRecycleViewAdapter(List<Goods> list) {
        this.mList = list;
    }

    @Override
    public ShowGoodsRecycleViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_show_goods, null);
        final ShowGoodsRecycleViewAdapter.ViewHolder holder = new ShowGoodsRecycleViewAdapter.ViewHolder(view);
        return holder;
    }

    //将数据绑定到控件上
    @Override
    public void onBindViewHolder(ShowGoodsRecycleViewAdapter.ViewHolder holder, int position) {
        Goods bean = mList.get(position);
        Glide.with(holder.myView).load(bean.getPic()).into(holder.imageView1);
        holder.title.setText(bean.getName());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

}
